<?php
/**
 * Created by PhpStorm.
 * User: yanghe
 * Date: 2016/5/9
 * Time: 13:29
 */
namespace App\Http\Controllers\Admin;

use Illuminate\Support\Facades\Request;
use Illuminate\Routing\Controller;
use MyClass\Admin\ArticleBase;
use MyClass\Admin\ArticleClassBase;


class ArticleController extends Controller
{

    public function addArticle()
    {
        session(["nowPage"=>"/user_aArticle"]);
        $data=ArticleClassBase::sClass();
        $res["data"]=$data;
        return view("Admin.Article.aArticle",$res);
    }


    public function _addArticle()
    {
        $input=Request::only("article_title","article_intro","article_detail","article_class");
        $data["article_intro"]=$input["article_intro"];
        $data["article_title"]=$input["article_title"];
        $data["article_detail"]=$input["article_detail"];
        $data["article_class"]=$input["article_class"];
        $data["article_click"]=0;
        $res=ArticleBase::addArticle($data);
        if($res)
        {
            return redirect("/user_sArticle");
        }
        else
        {
            return "失败";
        }
    }


    public function sArticle()
    {
        session(["nowPage"=>"/user_sArticle"]);
        $data=ArticleBase::sAllArticle();
        $article_class=ArticleClassBase::sClass();
        $data["article_class"]=$article_class;

//        dump($data);
//        exit();
        return view("Admin.Article.sArticle",$data);
    }


    public function uArticle($article_id)
    {
        $a=new ArticleBase($article_id);
        $data=$a->sArticle();
        $class=ArticleClassBase::sClass();
        $res["data"]=$data;
        $res["class"]=$class;
        return view("Admin.Article.uArticle",$res);
    }


    public function _uArticle()
    {
        $data=Request::only("article_title","article_intro","article_detail","id","article_class");
        $input["article_class"]=$data['article_class'];
        $input["article_title"]=$data["article_title"];
        $input["article_intro"]=$data["article_intro"];
        $input["article_detail"]=$data["article_detail"];
        $a=new ArticleBase($data["id"]);
        $res=$a->uArticle($input);
        if($res)
        {
            return redirect("/user_sArticle");
        }
        else
        {
            return false;
        }
    }
    public function dArticle($article_id)
    {
        $a=new ArticleBase($article_id);
        $res=$a->dArticle();
        if($res)
        {
            return redirect("/user_sArticle");
        }
        else
        {
            return false;
        }
    }
    public function _sArticle()
    {
        $article_id=Request::input("article_id");
        $a = new ArticleBase($article_id);
        $data=$a->sArticle();
        $res["data"]=$data;
        if($res)
        {
            return view("Admin.Article.fArticle",$res);
        }
        else
        {
            return false;
        }
    }
}